﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace iTeamyou.LTS.Core.Migrations
{
    public partial class Update1009 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropPrimaryKey(
                name: "PK_ManufacturerLicenseAttachments",
                table: "ManufacturerLicenseAttachments");

            migrationBuilder.DropPrimaryKey(
                name: "PK_BatchLicenseAttachments",
                table: "BatchLicenseAttachments");

            migrationBuilder.DropColumn(
                name: "ProductName",
                table: "BatchLicenses");

            migrationBuilder.DropColumn(
                name: "SKU",
                table: "BatchLicenses");

            migrationBuilder.DropColumn(
                name: "SupplierName",
                table: "BatchLicenses");

            migrationBuilder.RenameColumn(
                name: "Tag",
                table: "BatchLicenses",
                newName: "Type");

            migrationBuilder.AddColumn<int>(
                name: "Department",
                table: "Products",
                type: "int",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "SectionId",
                table: "Products",
                type: "longtext",
                nullable: true)
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "BatchId",
                table: "BatchLicenses",
                type: "varchar(95)",
                nullable: false,
                defaultValue: "")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddPrimaryKey(
                name: "PK_ManufacturerLicenseAttachments",
                table: "ManufacturerLicenseAttachments",
                columns: new[] { "Id", "LicenseId" });

            migrationBuilder.AddPrimaryKey(
                name: "PK_BatchLicenseAttachments",
                table: "BatchLicenseAttachments",
                columns: new[] { "Id", "LicenseId" });

            migrationBuilder.CreateTable(
                name: "Batches",
                columns: table => new
                {
                    Id = table.Column<string>(type: "varchar(95)", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Number = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Quantity = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    StoreId = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    StoreName = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    SupplierId = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    ProductId = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    OrderNumber = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    EntryDatetime = table.Column<DateTime>(type: "datetime", nullable: true),
                    WarehouseNumber = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    ValidDate = table.Column<DateTime>(type: "datetime", nullable: true),
                    DateDue = table.Column<DateTime>(type: "datetime", nullable: true),
                    ProducedDate = table.Column<DateTime>(type: "datetime", nullable: true),
                    CreatedOn = table.Column<DateTime>(type: "datetime", nullable: true),
                    CreatedBy = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    LastModifiedOn = table.Column<DateTime>(type: "datetime", nullable: true),
                    LastModifiedBy = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Batches", x => x.Id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_BatchLicenses_BatchId",
                table: "BatchLicenses",
                column: "BatchId");

            migrationBuilder.AddForeignKey(
                name: "FK_BatchLicenses_Batches_BatchId",
                table: "BatchLicenses",
                column: "BatchId",
                principalTable: "Batches",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_BatchLicenses_Batches_BatchId",
                table: "BatchLicenses");

            migrationBuilder.DropTable(
                name: "Batches");

            migrationBuilder.DropPrimaryKey(
                name: "PK_ManufacturerLicenseAttachments",
                table: "ManufacturerLicenseAttachments");

            migrationBuilder.DropIndex(
                name: "IX_BatchLicenses_BatchId",
                table: "BatchLicenses");

            migrationBuilder.DropPrimaryKey(
                name: "PK_BatchLicenseAttachments",
                table: "BatchLicenseAttachments");

            migrationBuilder.DropColumn(
                name: "Department",
                table: "Products");

            migrationBuilder.DropColumn(
                name: "SectionId",
                table: "Products");

            migrationBuilder.DropColumn(
                name: "BatchId",
                table: "BatchLicenses");

            migrationBuilder.RenameColumn(
                name: "Type",
                table: "BatchLicenses",
                newName: "Tag");

            migrationBuilder.AddColumn<string>(
                name: "ProductName",
                table: "BatchLicenses",
                type: "longtext",
                nullable: false)
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "SKU",
                table: "BatchLicenses",
                type: "longtext",
                nullable: false)
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "SupplierName",
                table: "BatchLicenses",
                type: "longtext",
                nullable: false)
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddPrimaryKey(
                name: "PK_ManufacturerLicenseAttachments",
                table: "ManufacturerLicenseAttachments",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_BatchLicenseAttachments",
                table: "BatchLicenseAttachments",
                column: "Id");
        }
    }
}
